angular.module('starter.controllers')
.controller('HomeCtrl', function($scope, museumFac, $stateParams, $timeout, $location, cfg, $cookies, uploadImg) {
	$scope.change_language = function(id){
	    $scope.language = id;
	    var expireDate = new Date();  
		expireDate.setDate(expireDate.getDate() + 30);                
		$cookies.put('language', id, {'expires': expireDate.toUTCString()});
		location.reload();
		if(id == 0){
			document.getElementById('title').innerHTML = '提示';
			document.getElementById('windowclosebutton').value = '确定';
		}else{
			document.getElementById('title').innerHTML = 'Hint';
			document.getElementById('windowclosebutton').value = 'Confirm';
		}

	}

	$scope.getLanguage = function(){
    	$scope.language = $cookies.get('language');
    	if($scope.language){
      		$scope.language = $scope.language;
    	}else{
      		$scope.language = 0;
    	}
    	if($scope.language == 0){
			document.getElementById('title').innerHTML = '提示';
			document.getElementById('windowclosebutton').value = '确定';
		}else{
			document.getElementById('title').innerHTML = 'Hint';
			document.getElementById('windowclosebutton').value = 'Confirm';
		}
  	}
  	$scope.getLanguage();

	$scope.gotoTicket = function(exhibitionId){
		window.location.href = cfg.baseUrl + 'home/index/exhibition?exhibitionId=' + exhibitionId;
	}

	$scope.backhome = function(){
		$location.url('home');
	}

	$scope.checkOpenid = function(){
        $scope.url = cfg.baseUrl + 'home/index/index';
        wx.ready(function(){
          wx.onMenuShareTimeline({
            title: '四方当代美术馆 | 线上商店', // 分享标题
            desc: ' ', // 分享描述
            link: $scope.url, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
            imgUrl: 'http://store.sifangartmuseum.org.cn/Public/museum/www/img/logo.png', // 分享图标
            success: function () { 
                // 用户确认分享后执行的回调函数
            },
            cancel: function () { 
                // 用户取消分享后执行的回调函数
            }
        });
        // 获取“分享给朋友”按钮点击状态及自定义分享内容接口
        wx.onMenuShareAppMessage({
            title: '四方当代美术馆 | 线上商店',  // 分享标题
            desc: ' ', // 分享描述
            link: $scope.url, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
            imgUrl: 'http://store.sifangartmuseum.org.cn/Public/museum/www/img/logo.png', // 分享图标
            type: '', // 分享类型,music、video或link，不填默认为link
            dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
            success: function () { 
                // 用户确认分享后执行的回调函数
            },
            cancel: function () { 
                // 用户取消分享后执行的回调函数
            }
          });
        });
	}
	$scope.checkOpenid();

	$scope.gotoCenter = function(){
		museumFac.user.usertest(function(data){
			if(data.info == true){
				$location.url('center');
			}else{
				$scope.url = window.location.href;
	      		$cookies.put('lastPage', $scope.url);
				$location.url('login');
			}
		});
	}

	$scope.gotoBanner = function(){
		museumFac.info.indexbanner(function(data){
			$scope.banners = data.info;

			$timeout(function() {
				var mySwiper = new Swiper('.swiper-container',{
				  pagination : '.swiper-pagination',
				  //pagination : '#swiper-pagination1',
				})
			}, 50);
			
		});
	}
	$scope.gotoBanner();

	$scope.gotoYansheng = function(){
		$location.url('productlist/1');
	}

	$scope.gotoProject = function(){
		window.location.href = 'http://store.sifangartmuseum.org.cn/Home/Index/productDetail?productId=12';
	}

	$scope.gotoVip = function(){
		window.location.href = 'http://store.sifangartmuseum.org.cn/Home/Index/vip';
	}

	$scope.gotoBanner = function(banner){
		window.location.href = banner.link;
	}

	// $scope.gotoBook = function(){
	// 	$location.url('productlist/2');
	// }

	$scope.gotoShop = function(){
		$location.url('shop');
	}
  
})